import store from "@/store";

import { message } from "ant-design-vue";

import { getTokenByUrl } from "@/utils"

import { settingConfig } from '@/config'

export const ssoLogin = (router) => {
    store.commit('app/changeLoading', true)
    /*
        第一种方式
    */
    const url = window.location.search;
    const searchParams = new URLSearchParams(url);
    const token = searchParams.get("token");

    /*
        第二种方式
    */
    // const value = window.location.href;
    // const token = getTokenByUrl(value);

    if (!token) {
        console.error("error: Not_Token");
        return false;
    }
    store.commit('app/changeLoading', false)
    store.dispatch("user/ssoLoginHandler", { token }).then(() => {
        message.success("登录成功");
        router.push({
            name: settingConfig.mainName
        })
    });
};
